home *** CD-ROM | disk | FTP | other *** search
Text File | 1995-07-28 | 3.1 KB | 143 lines | [TEXT/MPS ] |
- /*
- File: VirtualFile.cp
-
- Copyright: © 1991-1994 by Apple Computer, Inc.
- All rights reserved.
-
- Part of the AOCE Sample SMSAM Package. Consult the license
- which came with this software for your specific legal rights.
-
- */
-
-
-
- #ifndef __VIRTUALFILE__
- #include "VirtualFile.h"
- #endif
-
- #ifndef __DEBUGGINGGEAR__
- #include "DebuggingGear.h"
- #endif
-
- #pragma segment VirtualFile
-
- ImplementList(TVirtualFile,TVirtualFileList,true);
-
- ostream& TVirtualFile::operator >> ( ostream& s ) const
- {
- TAbstractFile::operator >> ( s );
- return s << ", count " << fReferenceCount;
- }
-
- //--------------------------------------------------------------------------------
-
- TVirtualFile::TVirtualFile() :
- TAbstractFile (),
- fUserRef ( 0 ),
- fReferenceCount ( 0 ),
- fAutoDispose ( true )
- {
- UpdateUsage();
- }
-
- //--------------------------------------------------------------------------------
-
- TVirtualFile::TVirtualFile( const TVirtualFile& that ):
- TAbstractFile ( that ),
- fUserRef ( 0 ),
- fReferenceCount ( 0 ),
- fAutoDispose ( true )
- {
- UpdateUsage();
- }
-
- //--------------------------------------------------------------------------------
-
- TVirtualFile&
- TVirtualFile::operator = ( const TVirtualFile& that )
- {
- TAbstractFile::operator = ( that );
- return *this;
- }
-
- //--------------------------------------------------------------------------------
-
- TVirtualFile::~TVirtualFile() // destructor
- {
- }
-
- //--------------------------------------------------------------------------------
-
- void TVirtualFile::SetUserRef(long ref)
- {
- fUserRef = ref;
- }
-
- //--------------------------------------------------------------------------------
-
- long TVirtualFile::GetUserRef() const {
- return fUserRef;
- }
-
- //--------------------------------------------------------------------------------
- // Increment the count of references to this object
-
- void TVirtualFile::RegisterReference()
- {
- fReferenceCount++;
- }
-
- //--------------------------------------------------------------------------------
- // Decrement the count of references to this object
- // If the count reaches zero and fAutoDispose is true
- // Then the object deletes itself
-
- void TVirtualFile::UnregisterReference()
- {
- fReferenceCount--;
-
- if (fReferenceCount<=0)
- {
- if (fAutoDispose) {
- #if debug
- if (steveFlag.Flag(18)) {
- steve << "TVirtualFile::UnregisterReference, fRefCount decremented to 0; deleting file." << endl;
- }
- #endif
- delete this;
- } else {
- fReferenceCount=0;
- }
- }
- }
-
- //--------------------------------------------------------------------------------
-
- Boolean TVirtualFile::GetAutoDispose() const
- {
- return fAutoDispose;
- }
-
- //--------------------------------------------------------------------------------
-
- void TVirtualFile::SetAutoDispose(Boolean doDispose)
- {
- fAutoDispose = doDispose;
- }
-
- //--------------------------------------------------------------------------------
-
- void TVirtualFile::UpdateUsage()
- {
- fLastUsed = TickCount ();
- }
-
- //--------------------------------------------------------------------------------
-
- long TVirtualFile::LastUsed() const
- {
- return fLastUsed;
- }
-
- /***********************************|****************************************/
-